package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysRegion;
import com.ruoyi.system.domain.vo.SysRegionVO;
import com.ruoyi.system.service.ISysRegionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 行政区划Controller
 *
 * @author kerwincui
 * @date 2024-07-29
 */
@RestController
@RequestMapping("/system/region")
public class SysRegionController extends BaseController
{
    @Autowired
    private ISysRegionService sysRegionService;

    /**
     * 查询行政区划列表
     */
    @ApiOperation("行政区划树")
    @GetMapping("/list")
    public AjaxResult list(SysRegion sysRegion) {
        sysRegion.setCode("44");
        List<SysRegionVO> list = sysRegionService.selectSysRegionList(sysRegion);
        return success(list);
    }

    /**
     * 获取行政区划详细信息
     */
    @PreAuthorize("@ss.hasPermi('iot:region:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(sysRegionService.selectSysRegionByCode(code));
    }

    /**
     * 新增行政区划
     */
    @PreAuthorize("@ss.hasPermi('iot:region:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SysRegion sysRegion)
    {
        return toAjax(sysRegionService.insertSysRegion(sysRegion));
    }

    /**
     * 修改行政区划
     */
    @PreAuthorize("@ss.hasPermi('iot:region:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SysRegion sysRegion)
    {
        return toAjax(sysRegionService.updateSysRegion(sysRegion));
    }

    /**
     * 删除行政区划
     */
    @PreAuthorize("@ss.hasPermi('iot:region:remove')")
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(sysRegionService.deleteSysRegionByCodes(codes));
    }
}
